//
//  AddressField.m
//  tour
//
//  Created by 123 on 16/5/16.
//  Copyright © 2016年 Jushi. All rights reserved.
//

#import "AddressField.h"

@interface AddressField()

@property (nonatomic,weak) UILabel *placeHolderLab;

@end
@implementation AddressField

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self addLabel];
    }
    return self;
}
- (void)awakeFromNib
{
    [super awakeFromNib];
    [self addLabel];
}
- (void)addLabel
{
    UILabel *placeHolderLab = [[UILabel alloc]init];
    placeHolderLab.font = [UIFont systemFontOfSize:16];
    placeHolderLab.textColor = RGBColorOne(200);
    placeHolderLab.text = @"请输入";
    self.placeHolderLab = placeHolderLab;
    [self addSubview:placeHolderLab];
    
    self.layer.borderColor = [UIColor colorWithRed:222/255.0 green:222/255.0 blue:222/255.0 alpha:1.0].CGColor;
    self.layer.borderWidth = 0.7;
    self.layer.cornerRadius = 5.0;
    self.clipsToBounds = YES;
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textChanged:) name:UITextViewTextDidChangeNotification object:nil];
}
- (void)setBorderWidth:(float)borderWidth
{
    _borderWidth = borderWidth;
    self.layer.borderWidth = borderWidth;
}
- (void)textChanged:(NSNotification *)noti
{
    AddressField *field = noti.object;
    if (field.text.length<1) {
        self.placeHolderLab.hidden = NO;
    }else{
        self.placeHolderLab.hidden = YES;
    }
}
- (void)setText:(NSString *)text
{
    [super setText:text];
    self.placeHolderLab.hidden = YES;
}
- (void)setPlaceHolder:(NSString *)placeHolder
{
    _placeHolder = placeHolder;
    self.placeHolderLab.text = placeHolder;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.placeHolderLab.frame = CGRectMake(5, 8, self.width-10, 17);
}

@end
